package com.gjzhao.fmmall.controller;

import com.gjzhao.fmmall.service.UserLoginService;
import com.gjzhao.fmmall.vo.RespResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户登录处理Controller
 * - controller层只做调用，不进行业务处理
 * @Author: gjzhao
 * @Date Created in 2022-02-12 2:40 下午
 */
@RestController
@CrossOrigin //该服务面向前端 需要增加 @CrossOrigin 注解处理跨越问题
@RequestMapping("/user")
@Api(value = "操作用户接口", tags = "用户管理-登录用户")
public class UserLoginController extends BaseController {


    @Autowired
    private UserLoginService userLoginService;


    @GetMapping("/loginByToken")
    @ApiOperation(value = "登录用户(使用token方式)")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "用户名", name = "username", dataType = "string", required = true),
        @ApiImplicitParam(value = "密码", name = "password", dataType = "string", required = true)
    })
    public RespResultVO getUserByToken(@RequestParam("username") String username,
                                       @RequestParam("password") String password) {
        RespResultVO resultVO = userLoginService.login(username, password);
        return resultVO;
    }

}
